﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using System.IO;
using System.Data;
using System.Text.RegularExpressions;
using System.Threading;
using System.Globalization;
using Abhiruchi_Phase1;
using EmployeeForm;
using System.Net;
using Abhiruchi_Phase1.BAL_DAL.HRM_DAL;

namespace Abhiruchi_Phase1
{
    /// <summary>
    /// Interaction logic for HRM_EmpOrganizational.xaml
    /// </summary>
    public partial class UC_HRM_EmpOrganizational : UserControl
    {
        private string FormType;
        private string EmpType;
        private string EmpId;


        public static string HQCertfPath = null;
        public static string PrevEmpCertfPath = null;
        public static string ResumePath = null;
        List<EmpIdNames> empList;
        List<string> idList;
        List<string> nameList;
        List<string> idNames;
        //for testing
        public static List<TestCase> tstCaseObj = new List<TestCase>();

        public static List<LinkPaths> lstPaths = new List<LinkPaths>();

        public static string tempPath = "";

        public static List<string> delPaths = new List<string>();

        // public static string path; 

        public UC_HRM_EmpOrganizational(string mode, string eid, string ftype)
        {
            //ftype = "Edit";
            //eid = "PE000006";
            InitializeComponent();
            initializeContentOrg(mode, eid, ftype);
        }

        #region initialize content
        public void initializeContentOrg(string mode, string eid, string ftype)
        {

            #region initialize data fields
            txtOtherQual.Text = "";
            txtPrevEmp.Text = "";
            txtRecruitedBy.Text = "";
            txtReferedBy.Text = "";
            txtRefNO.Text = "";
            txtReportingTo.Text = "";
            txtYOP.Text = "";
            HQCertfPath = null;
            PrevEmpCertfPath = null;
            ResumePath = null;
            #endregion

            FormType = ftype;
            if (mode == "Permanent Employee")
            {
                EmpType = "PE";
            }
            else if (mode == "Contract Employee")
            {
                EmpType = "CE";
            }


            EmpId = eid;
            if (EmpType == "PE")
            {
                grdqulf.Visibility = Visibility.Visible;
                docgrid.Visibility = Visibility.Visible;
            }
            else
            {
                grdqulf.Visibility = Visibility.Hidden;
                docgrid.Visibility = Visibility.Hidden;

            }

            HQCertfPath = null;
            PrevEmpCertfPath = null;
            ResumePath = null;
            dpDOJ.SelectedDate = System.DateTime.Now;

            if (EmpType == "CE")
            {
                grdqulf.Visibility = Visibility.Hidden;
                docgrid.Visibility = Visibility.Hidden;
            }


            // var mylist = OrganizationDAL.GetEmployees();
            empList = OrganizationDAL.GetEmployeeMasterEmployeeList();
            idList = new List<string>();
            nameList = new List<string>();
            idNames = new List<String>();

            for (int i = 0; i < empList.Count; i++)
            {
                idList.Add(empList[i].id);
                nameList.Add(empList[i].name);
                idNames.Add(empList[i].id);
                idNames.Add(empList[i].name);
            }

            txtReportingTo.ItemsSource = idNames;

            txtRecruitedBy.ItemsSource = idNames;
            lblOtherQual.Visibility = Visibility.Hidden;

            lblEmpId.Content = EmpId;

            #region Button
            if (FormType != "Edit")
            {
                ViewHqCertf.Visibility = Visibility.Hidden;
                btnRemoveHq.Visibility = Visibility.Hidden;
                ViewPrevEmpCertf.Visibility = Visibility.Hidden;
                btnRemovePe.Visibility = Visibility.Hidden;
                ViewResumeCertf.Visibility = Visibility.Hidden;
                btnRemoveResume.Visibility = Visibility.Hidden;
            }
            else
            {

                ClearForm();
                ShoworEditForm();
            }
            #endregion


        }
        #endregion

        public void ShoworEditForm()
        {
            if (EmpType == "PE")
            {
                GetDataFromDB();
            }
            else if (EmpType == "CE")
            {
                grdqulf.Visibility = Visibility.Collapsed;
                docgrid.Visibility = Visibility.Collapsed;
                GetDataFromDB();
            }
        }
        public void GetDataFromDB()
        {
            if (FormType == "Edit")
            {
                DataTable mydt = OrganizationDAL.GetOrganizationUpdate(EmpId);
                if (mydt.Rows.Count > 0)
                {
                    lblEmpId.Content = EmpId;
                    dpDOJ.Text = mydt.Rows[0][1].ToString();
                    cmbDesignation.Text = mydt.Rows[0][2].ToString();
                    txtReportingTo.Text = mydt.Rows[0][3].ToString();
                    txtRecruitedBy.Text = mydt.Rows[0][4].ToString();

                    txtReportingTo_LostFocus(null, null);
                    txtRecruitedBy_LostFocus(null, null);

                    cmbQualification.Text = mydt.Rows[0][5].ToString();
                    txtOtherQual.Text = mydt.Rows[0][6].ToString();
                    txtPrevEmp.Text = mydt.Rows[0][7].ToString();
                    if (mydt.Rows[0][8].ToString() == "0.00" && mydt.Rows[0][7].ToString() == "")
                    {
                        txtYOP.Text = "";
                    }
                    else
                    {

                        txtYOP.Text = mydt.Rows[0][8].ToString();
                    }
                    txtReferedBy.Text = mydt.Rows[0][9].ToString();
                    txtRefNO.Text = mydt.Rows[0][10].ToString();

                    //modified
                    HQCertfPath = mydt.Rows[0][11].ToString();
                    PrevEmpCertfPath = mydt.Rows[0][12].ToString();
                    ResumePath = mydt.Rows[0][13].ToString();
                    String[] x1 = HQCertfPath.Split('/');
                    lblHQNA.Content = SplitByLength(x1[x1.Length - 1], 20);

                    if (HQCertfPath != null && HQCertfPath != "")
                    {
                        HQCertfPath = HQCertfPath;
                        btnRemoveHq.Visibility = Visibility.Visible;
                        ViewHqCertf.Visibility = Visibility.Visible;
                        btnHighQualUpload.Visibility = Visibility.Hidden;
                    }
                    else
                    {
                        btnRemoveHq.Visibility = Visibility.Hidden;
                        ViewHqCertf.Visibility = Visibility.Hidden;
                        btnHighQualUpload.Visibility = Visibility.Visible;
                    }

                    String[] x2 = PrevEmpCertfPath.Split('/');
                    lblPrevEmpNA.Content = SplitByLength(x2[x2.Length - 1], 20);

                    if (PrevEmpCertfPath != null && PrevEmpCertfPath != "")
                    {
                        PrevEmpCertfPath = PrevEmpCertfPath;
                        btnRemovePe.Visibility = Visibility.Visible;
                        ViewPrevEmpCertf.Visibility = Visibility.Visible;
                        btnPrevEmpUpload.Visibility = Visibility.Hidden;
                    }
                    else
                    {
                        btnRemovePe.Visibility = Visibility.Hidden;
                        ViewPrevEmpCertf.Visibility = Visibility.Hidden;
                        btnPrevEmpUpload.Visibility = Visibility.Visible;
                    }

                    String[] x3 = ResumePath.Split('/');
                    lblResumeNA.Content = SplitByLength(x3[x3.Length - 1], 20);
                    if (ResumePath != null && ResumePath != "")
                    {
                        ResumePath = ResumePath;
                        btnRemoveResume.Visibility = Visibility.Visible;
                        ViewResumeCertf.Visibility = Visibility.Visible;
                        btnResumeUpload.Visibility = Visibility.Hidden;
                    }
                    else
                    {
                        btnRemoveResume.Visibility = Visibility.Hidden;
                        ViewResumeCertf.Visibility = Visibility.Hidden;

                        btnResumeUpload.Visibility = Visibility.Visible;
                    }
                    //EndModified

                }
            }
            //else 
            //{
            //    OrganizationDAL.GetOrganization(lblEmpId.Content.ToString(), cmbDesignation.SelectionBoxItem.ToString(), txtReportingTo.Text, txtRecruitedBy.Text, cmbQualification.SelectionBoxItem.ToString(), txtOtherQual.Text, txtPrevEmp.Text, double.Parse(txtYOP.Text), txtReferedBy.Text, txtRefNO.Text);
            //}
        }
        public string SplitByLength(string s, int count)
        {
            if (count > s.Length)
            {
                return s;
            }

            string[] dotSplit = s.Split('.');
            string splittedString = "";
            for (int i = 0; i < count && i < s.Length; i++)
            {
                splittedString += s[i];
            }

            if (s.Length - 3 > count)
            {
                return splittedString + "." + dotSplit[dotSplit.Length - 1];
            }
            return splittedString;
        }
        public void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // bool vald = validateForm();
            //if (vald == false)
            //{
            //    return;
            //}

            string reportToId = txtReportingTo.Text, reqruitedById=txtRecruitedBy.Text;

            if (txtReportingTo.Text != "")
            {
                for (int i = 0; i < empList.Count; i++)
                {
                    if (txtReportingTo.Text.ToUpper() == empList[i].name.ToUpper())
                    {
                        reportToId = empList[i].id;
                        break;
                    }
                }
            }

            if (txtRecruitedBy.Text != "")
            {
                for (int i = 0; i < empList.Count; i++)
                {
                    if (txtRecruitedBy.Text.ToUpper() == empList[i].name.ToUpper())
                    {
                        reqruitedById = empList[i].id;
                        break;
                    }
                }
            }



            if (FormType == "New")
            {
                if (EmpType == "PE")
                {
                    DeletePreviousFiles();
                    MoveFiles();


                    HQCertfPath = CheckPathsToInsertDb("HQ");
                    PrevEmpCertfPath = CheckPathsToInsertDb("PrevEmp");
                    ResumePath = CheckPathsToInsertDb("Resume");

                    OrganizationDAL.GetOrganization(lblEmpId.Content.ToString(), dpDOJ.Text, cmbDesignation.SelectionBoxItem.ToString(), reportToId, reqruitedById, cmbQualification.SelectionBoxItem.ToString(), txtOtherQual.Text, txtPrevEmp.Text, txtYOP.Text, txtReferedBy.Text, txtRefNO.Text, HQCertfPath, PrevEmpCertfPath, ResumePath);
                    // MessageBox.Show("Record Inserted");
                }
                else if (EmpType == "CE")
                {

                    OrganizationDAL.GetOrganization(lblEmpId.Content.ToString(), dpDOJ.Text, cmbDesignation.SelectionBoxItem.ToString(), reportToId, reqruitedById, "", "", txtPrevEmp.Text, txtYOP.Text, txtReferedBy.Text, txtRefNO.Text, "", "", "");
                    //  MessageBox.Show("Record Inserted");
                }
            }
            else if (FormType == "Edit")
            {
                if (EmpType == "PE")
                {
                    DeletePreviousFiles();
                    MoveFiles();


                    HQCertfPath = CheckPathsToInsertDb("HQ");
                    PrevEmpCertfPath = CheckPathsToInsertDb("PrevEmp");
                    ResumePath = CheckPathsToInsertDb("Resume");

                    OrganizationDAL.GetOrgantionUpdate(lblEmpId.Content.ToString(), dpDOJ.Text, cmbDesignation.SelectionBoxItem.ToString(), reportToId, reqruitedById, cmbQualification.SelectionBoxItem.ToString(), txtOtherQual.Text, txtPrevEmp.Text, txtYOP.Text, txtReferedBy.Text, txtRefNO.Text, HQCertfPath, PrevEmpCertfPath, ResumePath);
                    //   MessageBox.Show("Record Updated");
                }
                else if (EmpType == "CE")
                {

                    OrganizationDAL.GetOrgantionUpdate(lblEmpId.Content.ToString(), dpDOJ.Text, cmbDesignation.SelectionBoxItem.ToString(), reportToId, reqruitedById, "", "", txtPrevEmp.Text, txtYOP.Text, txtReferedBy.Text, txtRefNO.Text, "", "", "");
                    // MessageBox.Show("Record Updated");
                }
            }
            try
            {
                tempPath = joinPath("") + "PersonalTemp";
                if (tempPath != null && tempPath != "")
                {
                    string[] filePaths = Directory.GetFiles(tempPath);
                    foreach (string filePath in filePaths)
                        File.Delete(filePath);
                }
            }
            catch (Exception ex)
            {
            }

            lstPaths.Clear();
            delPaths.Clear();

            //HQCertfPath = null;
            //PrevEmpCertfPath = null;
            //ResumePath = null;

            try
            {
                if (tempPath != null && tempPath != "")
                {
                    string[] filePaths = Directory.GetFiles(tempPath);
                    foreach (string filePath in filePaths)
                        File.Delete(filePath);
                }
            }
            catch (Exception ex) { }

            //GetDataFromDB();

            // ClearForm();
            //}

        }

        private void ClearForm()
        {
            cmbDesignation.SelectedIndex = 0;
            txtReportingTo.Text = "";
            txtRecruitedBy.Text = "";
            txtPrevEmp.Text = "";
            txtYOP.Text = "";
            txtReferedBy.Text = "";
            txtRefNO.Text = "";
            cmbQualification.SelectedIndex = 0;
            ViewHqCertf.Visibility = Visibility.Hidden;
            btnRemoveHq.Visibility = Visibility.Hidden;
            ViewPrevEmpCertf.Visibility = Visibility.Hidden;
            btnRemovePe.Visibility = Visibility.Hidden;
            ViewResumeCertf.Visibility = Visibility.Hidden;
            btnRemoveResume.Visibility = Visibility.Hidden;
            btnHighQualUpload.Visibility = Visibility.Visible;
            btnPrevEmpUpload.Visibility = Visibility.Visible;
            btnResumeUpload.Visibility = Visibility.Visible;
            lblHQNA.Content = "";
            lblPrevEmpNA.Content = "";
            lblResumeNA.Content = "";

        }

        #region Validation before Inserting
        public bool validateForm()
        {
            lblReportingTo.Foreground = System.Windows.Media.Brushes.DimGray;
            lblRecruitedBy.Foreground = System.Windows.Media.Brushes.DimGray;
            bool flag1 = false, flag2 = false;

            if ((txtReportingTo.Text != "" || txtRecruitedBy.Text != "") && empList.Count>0)
            {
                for (int i = 0; i < idNames.Count; i++)
                {
                    if (txtReportingTo.Text == idNames[i])
                    {
                        flag1 = true;
                        // break;
                    }
                    if (txtRecruitedBy.Text == idNames[i])
                    {
                        flag2 = true;
                        //break;
                    }
                }
            }
            if (empList.Count == 0)
            {
                flag1 = true;
                flag2 = true;
            }
            if (txtRecruitedBy.Text == "") flag2 = true;
            if (txtReportingTo.Text == "") flag1 = true;
            if (flag1 == false)
            {
                MessageBox.Show("Reporting to is Not a Valid Employee", "Reporting To", MessageBoxButton.OK, MessageBoxImage.Warning);
                lblReportingTo.Foreground = System.Windows.Media.Brushes.Red;
                txtReportingTo.Focus();
                return false;
            }
            if (flag2 == false)
            {
                MessageBox.Show("Recruited by is Not a Valid Employee", "Recruited By", MessageBoxButton.OK, MessageBoxImage.Warning);
                lblRecruitedBy.Foreground = System.Windows.Media.Brushes.Red;
                txtRecruitedBy.Focus();
                return false;
            }


            if (EmpType == "PE")
            {
                //Regex rx = new Regex(@"^(((((0[1-9])|(1\d)|(2[0-8]))\/((0[1-9])|(1[0-2])))|((31\/((0[13578])|(1[02])))|((29|30)\/((0[1,3-9])|(1[0-2])))))\/((20[0-9][0-9])|(19[0-9][0-9])))|((29\/02\/(19|20)(([02468][048])|([13579][26]))))$  ");
                //if (!rx.IsMatch(dpDOJ.Text))
                //{
                //    MessageBox.Show("Enter Correct Date");
                //    return false;
                //}
                lblRefNo.Foreground = System.Windows.Media.Brushes.DimGray;
                lblReferedBy.Foreground = System.Windows.Media.Brushes.DimGray;
                lblYearOfExp.Foreground = System.Windows.Media.Brushes.DimGray;
                lblReferedBy.Foreground = System.Windows.Media.Brushes.DimGray;
                lblPrevEmp.Foreground = System.Windows.Media.Brushes.DimGray;
                lblQualification.Foreground = System.Windows.Media.Brushes.DimGray;
                lblOtherQual.Foreground = System.Windows.Media.Brushes.DimGray;
                lblRecruitedBy.Foreground = System.Windows.Media.Brushes.DimGray;
                lblDesg.Foreground = System.Windows.Media.Brushes.DimGray;
                if (cmbDesignation.SelectedIndex == 0)
                {
                    MessageBox.Show("Select Designation", "Designation", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblDesg.Foreground = System.Windows.Media.Brushes.Red;
                    cmbDesignation.Focus();
                    return false;
                }

                if (txtRecruitedBy.Text == "")
                {
                    MessageBox.Show("recruited by is mandatory", "Recruited By", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblRecruitedBy.Foreground = System.Windows.Media.Brushes.Red;
                    txtRecruitedBy.Focus();
                    return false;
                }

                if (cmbQualification.SelectedIndex == 0)
                {
                    MessageBox.Show("Select Qualification", "Qualification", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblQualification.Foreground = System.Windows.Media.Brushes.Red;
                    cmbQualification.Focus();
                    return false;
                }
                else if (cmbQualification.SelectedIndex == 6 && txtOtherQual.Text == "")
                {
                    MessageBox.Show("Enter Other Qualification", "Other Qualification", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblOtherQual.Foreground = System.Windows.Media.Brushes.Red;
                    txtOtherQual.Focus();
                    return false;
                }

                if ((txtPrevEmp.Text != "" && txtYOP.Text == ""))
                {
                    MessageBox.Show("Enter Years of Experience", "Years of Experience", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblYearOfExp.Foreground = System.Windows.Media.Brushes.Red;
                    return false;
                }



                if (txtPrevEmp.Text == "" && (txtYOP.Text != "" && txtYOP.Text != "0.00"))
                {
                    MessageBox.Show("Enter Previous Employer", "Previous Employer", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblPrevEmp.Foreground = System.Windows.Media.Brushes.Red;
                    txtPrevEmp.Clear();
                    txtPrevEmp.Focus();
                    return false;
                }

                Regex nameRE = new Regex(@"^[a-zA-Z\s]+$");
                if (!nameRE.IsMatch(txtPrevEmp.Text) && txtPrevEmp.Text != "")
                {
                    MessageBox.Show("Enter Previous Employer Name Correctly", "Previous Employer", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblPrevEmp.Foreground = System.Windows.Media.Brushes.Red;
                    txtPrevEmp.Clear();
                    txtPrevEmp.Focus();
                    return false;
                }


                if (!nameRE.IsMatch(txtReferedBy.Text) && txtReferedBy.Text != "")
                {
                    MessageBox.Show("Enter Reference Name Correctly", "Referred By", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblReferedBy.Foreground = System.Windows.Media.Brushes.Red;
                    txtReferedBy.Clear();
                    txtReferedBy.Focus();
                    return false;
                }



                Regex exprefNoReg = new Regex(@"^\d{1,2}(\.\d{0,2})?$");

                if (!exprefNoReg.IsMatch(txtYOP.Text) && txtYOP.Text != "")
                {
                    MessageBox.Show("Enter Correct Years of Experience", "Years of Experience", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblYearOfExp.Foreground = System.Windows.Media.Brushes.Red;
                    txtYOP.Clear();
                    txtYOP.Focus();
                    return (false);
                }


                if (txtYOP.Text != "")
                {
                    string[] x = txtYOP.Text.Split('.');

                    int y = 0;


                    if (x.Length == 1)
                    {
                        y = 0;
                    }
                    else
                    {
                        y = Int32.Parse(x[1]);
                    }
                    if (Int32.Parse(x[0]) > 99 || y > 12)
                    {

                        MessageBox.Show("Enter Correct Years of Experience", "Years of Experience", MessageBoxButton.OK, MessageBoxImage.Warning);
                        lblYearOfExp.Foreground = System.Windows.Media.Brushes.Red;
                        txtYOP.Clear();
                        txtYOP.Focus();
                        return (false);
                    }
                }


                if (txtReferedBy.Text != "" && txtRefNO.Text == "")
                {
                    MessageBox.Show("Enter Reference Number", "Referred By", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblRefNo.Foreground = System.Windows.Media.Brushes.Red;
                    txtRefNO.Clear();
                    txtRefNO.Focus();
                    return false;
                }
                if (txtReferedBy.Text == "" && txtRefNO.Text != "")
                {
                    MessageBox.Show("Enter Reference Name", "Refered By", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblReferedBy.Foreground = System.Windows.Media.Brushes.Red;
                    txtReferedBy.Clear();
                    txtReferedBy.Focus();
                    return false;
                }

                Regex refNoReg = new Regex(@"\d+$");
                if (!refNoReg.IsMatch(txtRefNO.Text) && txtRefNO.Text != "")
                {
                    MessageBox.Show("Enter Correct Reference Number", "Reference Number", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblRefNo.Foreground = System.Windows.Media.Brushes.Red;
                    txtRefNO.Clear();
                    txtRefNO.Focus();
                    return (false);
                }

                return true;
            }
            else if (EmpType == "CE")
            {
                //Regex rx = new Regex(@"^(((((0[1-9])|(1\d)|(2[0-8]))\/((0[1-9])|(1[0-2])))|((31\/((0[13578])|(1[02])))|((29|30)\/((0[1,3-9])|(1[0-2])))))\/((20[0-9][0-9])|(19[0-9][0-9])))|((29\/02\/(19|20)(([02468][048])|([13579][26]))))$  ");
                //if (!rx.IsMatch(dpDOJ.Text))
                //{
                //    MessageBox.Show("Enter Correct Date");
                //    return false;
                //}
                lblRefNo.Foreground = System.Windows.Media.Brushes.DimGray;
                lblReferedBy.Foreground = System.Windows.Media.Brushes.DimGray;
                lblRefNo.Foreground = System.Windows.Media.Brushes.DimGray;

                lblYearOfExp.Foreground = System.Windows.Media.Brushes.DimGray;

                lblReferedBy.Foreground = System.Windows.Media.Brushes.DimGray;
                lblPrevEmp.Foreground = System.Windows.Media.Brushes.DimGray;
                lblPrevEmp.Foreground = System.Windows.Media.Brushes.DimGray;
                lblYearOfExp.Foreground = System.Windows.Media.Brushes.DimGray;
                lblDesg.Foreground = System.Windows.Media.Brushes.DimGray;
                if (cmbDesignation.SelectedIndex == 0)
                {
                    MessageBox.Show("Select Designation", "Designation", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblDesg.Foreground = System.Windows.Media.Brushes.Red;
                    cmbDesignation.Focus();
                    return false;
                }

                if (txtRecruitedBy.Text == "")
                {
                    MessageBox.Show("recruited by is mandatory", "Recruited By", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblRecruitedBy.Foreground = System.Windows.Media.Brushes.Red;
                    txtRecruitedBy.Focus();
                    return false;
                }
                lblRecruitedBy.Foreground = System.Windows.Media.Brushes.DimGray;

                if ((txtPrevEmp.Text != "" && txtYOP.Text == ""))
                {
                    MessageBox.Show("Enter Years of Experience", "Years of Experience", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblYearOfExp.Foreground = System.Windows.Media.Brushes.Red;
                    return false;
                }


                if ((txtPrevEmp.Text == "" && txtYOP.Text != "") && (txtPrevEmp.Text == "" || txtYOP.Text != "0.00"))
                {
                    MessageBox.Show("Enter Previous Employer", "Previous Employer", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblPrevEmp.Foreground = System.Windows.Media.Brushes.Red;
                    txtPrevEmp.Clear();
                    txtPrevEmp.Focus();
                    return false;
                }

                Regex nameRE = new Regex(@"^[a-zA-Z\s]+$");
                if (!nameRE.IsMatch(txtPrevEmp.Text) && txtPrevEmp.Text != "")
                {
                    MessageBox.Show("Enter Previous Employer Name Correctly", "Previous Employer", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblPrevEmp.Foreground = System.Windows.Media.Brushes.Red;
                    txtPrevEmp.Clear();
                    txtPrevEmp.Focus();
                    return false;
                }

                if (!nameRE.IsMatch(txtReferedBy.Text) && txtReferedBy.Text != "")
                {
                    MessageBox.Show("Enter Reference Name Correctly", "Reference Name", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblReferedBy.Foreground = System.Windows.Media.Brushes.Red;
                    txtReferedBy.Clear();
                    txtReferedBy.Focus();
                    return false;
                }

                Regex exprefNoReg = new Regex(@"^\d{1,2}(\.\d{0,2})?$");


                if (txtYOP.Text != "")
                {
                    string[] x = txtYOP.Text.Split('.');

                    int y = 0;


                    if (x.Length == 1)
                    {
                        y = 0;
                    }
                    else
                    {
                        y = Int32.Parse(x[1]);
                    }
                    if (Int32.Parse(x[0]) > 99 || y > 12)
                    {

                        MessageBox.Show("Enter Correct Years of Experience", "Years of Experience", MessageBoxButton.OK, MessageBoxImage.Warning);
                        lblYearOfExp.Foreground = System.Windows.Media.Brushes.Red;
                        txtYOP.Clear();
                        txtYOP.Focus();
                        return (false);
                    }
                }
                if (txtReferedBy.Text != "" && txtRefNO.Text == "")
                {
                    MessageBox.Show("Enter Reference Number", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblRefNo.Foreground = System.Windows.Media.Brushes.Red;
                    txtRefNO.Clear();
                    txtRefNO.Focus();
                    return false;
                }

                if (txtReferedBy.Text == "" && txtRefNO.Text != "")
                {
                    MessageBox.Show("Enter Reference Name", "Reference Name", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblReferedBy.Foreground = System.Windows.Media.Brushes.Red;
                    txtReferedBy.Clear();
                    txtReferedBy.Focus();
                    return false;
                }

                Regex refNoReg = new Regex(@"\d+$");
                if (!refNoReg.IsMatch(txtRefNO.Text) && txtRefNO.Text != "")
                {
                    MessageBox.Show("Enter Correct Reference Number", "Reference Number", MessageBoxButton.OK, MessageBoxImage.Warning);
                    lblRefNo.Foreground = System.Windows.Media.Brushes.Red;
                    txtRefNO.Clear();
                    txtRefNO.Focus();
                    return (false);
                }

                return true;
            }
            return true;
        }
        #endregion


        private void cmbQualification_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbQualification.SelectedIndex == 6)
            {
                txtOtherQual.Visibility = Visibility.Visible;
                lblQualification.Visibility = Visibility.Visible;

                lblOtherQual.Visibility = Visibility.Visible;
            }
            else
            {
                if (txtOtherQual != null)
                {

                    lblOtherQual.Visibility = Visibility.Hidden;
                    txtOtherQual.Visibility = Visibility.Hidden;
                    txtOtherQual.Text = "";
                }
            }

        }

        private void btnNext_Click(object sender, RoutedEventArgs e)
        {
            // GetList(); 
        }

        private void dpDOJ_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            CultureInfo culutreInfo = Thread.CurrentThread.CurrentCulture.Clone() as CultureInfo;
            culutreInfo.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
            Thread.CurrentThread.CurrentCulture = culutreInfo;


        }

        #region document upload code

        private void btnPrevEmpUpload_Click(object sender, RoutedEventArgs e)
        {
            PrevEmpCertfPath = AssignFilePath(lblPrevEmpNA);
            if (PrevEmpCertfPath == "duplicate")
            {
                return;
            }
            if (PrevEmpCertfPath != "0")
            {
                storeList("PrevEmp", PrevEmpCertfPath);
                #region btn
                btnPrevEmpUpload.Visibility = Visibility.Hidden;
                ViewPrevEmpCertf.Visibility = Visibility.Visible;
                btnRemovePe.Visibility = Visibility.Visible;
                #endregion
            }
        }

        private void btnResumeUpload_Click(object sender, RoutedEventArgs e)
        {
            ResumePath = AssignFilePath(lblResumeNA);
            if (ResumePath == "duplicate")
            {
                return;
            }
            if (ResumePath != "0")
            {
                storeList("Resume", ResumePath);
                #region btn
                btnResumeUpload.Visibility = Visibility.Hidden;
                ViewResumeCertf.Visibility = Visibility.Visible;
                btnRemoveResume.Visibility = Visibility.Visible;
                #endregion
            }
        }

        private void btnHighQualUpload_Click(object sender, RoutedEventArgs e)
        {
            HQCertfPath = AssignFilePath(lblHQNA);
            if (HQCertfPath == "duplicate")
            {
                return;
            }
            if (HQCertfPath != "0")
            {
                storeList("HQ", HQCertfPath);
                #region btn
                btnHighQualUpload.Visibility = Visibility.Hidden;
                ViewHqCertf.Visibility = Visibility.Visible;
                btnRemoveHq.Visibility = Visibility.Visible;
                #endregion
            }
        }

        private string AssignFilePath(Label lbl)
        {
            string path;
            var dlg = new OpenFileDialog();
            if (dlg.ShowDialog() == true)
            {
                new FileInfo(dlg.FileName);
                string newFileName;
                using (Stream s = dlg.OpenFile())
                {
                    TextReader reader = new StreamReader(s);
                    string st = reader.ReadToEnd();
                    string[] x;
                    x = dlg.FileName.Split('\\');
                    newFileName = x[x.Length - 1];


                    path = AppDomain.CurrentDomain.BaseDirectory;

                    string[] pathArray = path.Split(new char[] { '\\' });
                    path = string.Empty;
                    for (int temp = 0; temp < pathArray.Count() - 3; temp++)
                    {
                        if (temp == 0)
                            path = path + pathArray[temp];
                        else
                            path = path + "\\" + pathArray[temp];
                    }

                    path += "\\PersonalTemp\\";
                    tempPath = path;
                    // string newPath = System.IO.Path.Combine(path, EmpId);
                    //System.IO.Directory.CreateDirectory(newPath);
                    //path += EmpId + "\\";
                    path += newFileName;

                    if (File.Exists(path))
                    {
                        MessageBox.Show("Same File Cannot be uploaded again");
                        return "duplicate";
                    }


                    if (FormType == "Edit")
                    {
                        string esxtFilePath = joinPath("Documents\\Employees\\Permanent\\" + EmpId + "\\" + newFileName);
                        if (File.Exists(esxtFilePath))
                        {
                            bool flag = false;
                            for (int i = 0; i < delPaths.Count; i++)
                            {
                                string[] delName = delPaths[i].Split('\\');
                                if (delName[delName.Length - 1] == newFileName)
                                {
                                    flag = true;
                                }
                            }

                            if (flag == false)
                            {
                                MessageBox.Show("Same File Cannot be uploaded again");
                                return "duplicate";
                            }
                        }
                    }



                    if (!File.Exists(path))
                    {
                        File.Copy(dlg.FileName, path);

                        lbl.Content = SplitByLength(newFileName, 20);
                    }
                }


                return path;
            }
            return "0";
        }
        private void ViewHqCertf_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start(HQCertfPath);
            }
            catch (Exception ex) { }
        }

        private void btnRemoveHq_Click(object sender, RoutedEventArgs e)
        {
            if (FormType == "Edit")
            {
                if (HQCertfPath != null)
                {
                    delPaths.Add(HQCertfPath);
                    HQCertfPath = null;
                    lblHQNA.Content = "";


                }
                else if (lblHQNA.Content == "")
                {
                    removeHqnaNew();
                    return;
                }
                removeHqnaNew();
            }
            else
            {
                removeHqnaNew();
            }
            btnHighQualUpload.Visibility = Visibility.Visible;
            ViewHqCertf.Visibility = Visibility.Hidden;
            btnRemoveHq.Visibility = Visibility.Hidden;
        }
        public void removeHqnaNew()
        {


            for (int i = 0; i < lstPaths.Count; i++)
            {
                if (lstPaths[i].FILENAME == "HQ")
                {
                    File.Delete(lstPaths[i].FILEPATH);
                    lstPaths.RemoveAt(i);
                }
            }

            lblHQNA.Content = "";
        }

        private void btnRemoveResume_Click(object sender, RoutedEventArgs e)
        {
            if (FormType == "Edit")
            {
                if (ResumePath != null)
                {
                    delPaths.Add(ResumePath);
                    ResumePath = null;
                    lblResumeNA.Content = "";


                }
                else if (lblResumeNA.Content == "")
                {
                    removeResumeNew();
                    return;
                }
                removeResumeNew();
            }
            else
            {
                removeResumeNew();
            }
            btnResumeUpload.Visibility = Visibility.Visible;
            ViewResumeCertf.Visibility = Visibility.Hidden;
            btnRemoveResume.Visibility = Visibility.Hidden;
        }
        public void removeResumeNew()
        {

            for (int i = 0; i < lstPaths.Count; i++)
            {
                if (lstPaths[i].FILENAME == "Resume")
                {

                    File.Delete(lstPaths[i].FILEPATH);
                    lstPaths.RemoveAt(i);
                }
            }

            lblResumeNA.Content = "";
        }

        private void btnRemovePe_Click(object sender, RoutedEventArgs e)
        {



            if (FormType == "Edit")
            {
                if (PrevEmpCertfPath != null)
                {
                    delPaths.Add(PrevEmpCertfPath);
                    //File.Delete(PrevEmpCertfPath);
                    PrevEmpCertfPath = null;
                    lblPrevEmpNA.Content = "";

                }
                else if (lblPrevEmpNA.Content == "")
                {
                    removePeNew();
                    return;
                }

                removePeNew();
            }
            else
            {
                removePeNew();
            }
            btnPrevEmpUpload.Visibility = Visibility.Visible;
            ViewPrevEmpCertf.Visibility = Visibility.Hidden;
            btnRemovePe.Visibility = Visibility.Hidden;

        }

        public void removePeNew()
        {
            for (int i = 0; i < lstPaths.Count; i++)
            {
                if (lstPaths[i].FILENAME == "PrevEmp")
                {

                    File.Delete(lstPaths[i].FILEPATH);
                    lstPaths.RemoveAt(i);
                }
            }

            lblPrevEmpNA.Content = "";
        }

        private void ViewPrevEmpCertf_Click_1(object sender, RoutedEventArgs e)
        {
            try{
                System.Diagnostics.Process.Start(PrevEmpCertfPath);
            }
            catch (Exception ex) { }
        }

        private void ViewResumeCertf_Click_1(object sender, RoutedEventArgs e)
        {
            try{
            System.Diagnostics.Process.Start(ResumePath);
            }
            catch (Exception ex) { }
        }
        //EndModified

        public void storeList(string name, string path)
        {
            lstPaths.Add(new LinkPaths(name, path));
        }
        public void GetList()
        {
            string result = "";
            for (int i = 0; i < lstPaths.Count; i++)
            {
                result += lstPaths[i].fileName + lstPaths[i].FILEPATH + "#";
            }

            MessageBox.Show(result);
        }
        public void MoveFiles()
        {
            string path;
            //path = AppDomain.CurrentDomain.BaseDirectory;

            //string[] pathArray = path.Split(new char[] { '\\' });
            //path = string.Empty;
            //for (int temp = 0; temp < pathArray.Count() - 3; temp++)
            //{
            //    if (temp == 0)
            //        path = path + pathArray[temp];
            //    else
            //        path = path + "\\" + pathArray[temp];
            //}
            path = "ftp://118.139.163.181/";
            if (EmpType == "PE")
            {
                path += "Documents/Employees/Permanent/";
            }
            else
            {
                path += "/Documents/Employees/Contract/";
            }
            //string newPath = System.IO.Path.Combine(path, EmpId);
            //System.IO.Directory.CreateDirectory(newPath);
            //path += EmpId + "\\";

            for (int i = 0; i < lstPaths.Count; i++)
            {
                string pathTemp = path + EmpId + "/";
                string[] x = lstPaths[i].filePath.Split('\\');
                pathTemp += x[x.Length - 1];
                //if (!File.Exists(pathTemp))
                //{
                //  if (File.Exists(lstPaths[i].filePath))
                {
                    // File.Copy(lstPaths[i].filePath, pathTemp);
                    using (WebClient webClient = new WebClient())
                    {
                        webClient.UploadFile(pathTemp, lstPaths[i].FILEPATH);
                    }
                    lstPaths[i].filePath = pathTemp;
                }

                //File.Delete(lstPaths[i].filePath);
                //}
                //else
                //{
                //    lstPaths[i].filePath = pathTemp;
                //}
            }
        }
        public string CheckPathsToInsertDb(string name)
        {
            for (int i = 0; i < lstPaths.Count; i++)
            {
                if (lstPaths[i].FILENAME == name)
                { // editing

                    //string pathComplete = lstPaths[i].FILEPATH;
                    //string[] shortPath = Regex.Split(pathComplete, "Documents");

                    //string splittedPath = shortPath[1];
                    //shortPath[1] = "Documents" + shortPath[1];
                    //return shortPath[1];
                    return lstPaths[i].FILEPATH;

                }
            }

            if (name == "HQ" && lblHQNA.Content.ToString() != "" && lblHQNA.Content.ToString() != "NA")
                return HQCertfPath;
            else if (name == "PrevEmp" && lblPrevEmpNA.Content.ToString() != "" && lblPrevEmpNA.Content.ToString() != "NA")

                return PrevEmpCertfPath;
            else if (name == "Resume" && lblResumeNA.Content.ToString() != "" && lblResumeNA.Content.ToString() != "NA")
                return ResumePath;

            return null;

        }

        //no need if ftp used
        public string trimPath(string path)
        {
            string[] split = path.Split('\\');
            string[] shortPath = Regex.Split(path, "Documents");

            string splittedPath = shortPath[1];
            shortPath[1] = "Documents" + shortPath[1];

            if (shortPath.Length == 1)
            {
                if (FormType == "CE")
                    return "Documents" + "\\" + "Employees" + "\\" + "Contract" + "\\" + EmpId + "\\" + split[split.Length - 1];
                else
                    return "Documents" + "\\" + "Employees" + "\\" + "Permanent" + "\\" + EmpId + "\\" + split[split.Length - 1];
            }
            else
            {
                return shortPath[1];
            }
        }
        public void DeletePreviousFiles()
        {
            for (int i = 0; i < delPaths.Count; i++)
            {
                if (delPaths[i] != null && delPaths[i] != "")
                {
                    //File.Delete(delPaths[i]);
                    string[] x = delPaths[i].Split('/');
                    if (x[0] == "ftp:")
                    {
                        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(delPaths[i]);
                        request.Method = WebRequestMethods.Ftp.DeleteFile;

                        FtpWebResponse response = (FtpWebResponse)request.GetResponse();
                    }
                    else
                    {
                        File.Delete(delPaths[i]);
                    }

                }
            }
        }

        //no need if ftp used
        public string joinPath(string dbPath)
        {
            string path;
            path = AppDomain.CurrentDomain.BaseDirectory;

            string[] pathArray = path.Split(new char[] { '\\' });
            path = string.Empty;
            for (int temp = 0; temp < pathArray.Count() - 3; temp++)
            {
                if (temp == 0)
                    path = path + pathArray[temp];
                else
                    path = path + "\\" + pathArray[temp];
            }
            path = path + "\\" + dbPath;
            return path;
        }

        #endregion

        #region duplicate file check in ftp
        public bool CheckFTPFile(string fileName, string strFTPPath)
        {
            FtpWebRequest reqFTP;

            // dirName = name of the directory to create.

            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(strFTPPath));
            reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
            reqFTP.UseBinary = true;
            FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
            StreamReader ftpStream = new StreamReader(response.GetResponseStream());

            List<string> files = new List<string>();
            string line = ftpStream.ReadLine();
            while (line != null)
            {
                files.Add(line);
                line = ftpStream.ReadLine();
            }

            ftpStream.Close();
            response.Close();

            return files.Contains(fileName);
        }
        #endregion


        //private void button1_Click(object sender, RoutedEventArgs e)
        //{
        //    #region Temp Code
        //    if (rdoNEW.IsChecked == true)
        //    {
        //        FormType = "New";
        //        ClearForm();
        //    }
        //    else
        //    {
        //        FormType = "Edit";
        //    }

        //    if (rdoPE.IsChecked == true)
        //    {
        //        EmpType = "PE";
        //        grdqulf.Visibility = Visibility.Visible;
        //        docgrid.Visibility = Visibility.Visible;
        //    }
        //    else
        //    {
        //        EmpType = "CE";
        //        grdqulf.Visibility = Visibility.Hidden;
        //        docgrid.Visibility = Visibility.Hidden;

        //    }

        //    EmpId = txtTempEID.Text;

        //    #endregion

        //    HQCertfPath = null;
        //    PrevEmpCertfPath = null;
        //    ResumePath = null;
        //    dpDOJ.SelectedDate = System.DateTime.Now;

        //    if (EmpType == "CE")
        //    {
        //        grdqulf.Visibility = Visibility.Hidden;
        //        docgrid.Visibility = Visibility.Hidden;
        //    }

        //    if (tempPath != null && tempPath != "")
        //    {
        //        string[] filePaths = Directory.GetFiles(tempPath);
        //        foreach (string filePath in filePaths)
        //            File.Delete(filePath);
        //    }

        //    var mylist = OrganizationDAL.GetEmployees();

        //    txtReportingTo.ItemsSource = mylist;

        //    txtRecruitedBy.ItemsSource = mylist;
        //    lblOtherQual.Visibility = Visibility.Hidden;

        //    lblEmpId.Content = EmpId;
        //    ShoworEditForm();
        //    #region Button
        //    if (FormType != "Edit")
        //    {
        //        ViewHqCertf.Visibility = Visibility.Hidden;
        //        btnRemoveHq.Visibility = Visibility.Hidden;
        //        ViewPrevEmpCertf.Visibility = Visibility.Hidden;
        //        btnRemovePe.Visibility = Visibility.Hidden;
        //        ViewResumeCertf.Visibility = Visibility.Hidden;
        //        btnRemoveResume.Visibility = Visibility.Hidden;
        //    }
        //    #endregion
        //}


        #region Testing Code

        public class TestCase
        {
            public int TestId;
            public string TestCaseDesc;
            public bool IsPass;
        }
        private void btnAtTest_Click_1(object sender, RoutedEventArgs e)
        {

            tstCaseObj.Clear();
            Validate();
            string TestCaseLogSuccess = "";
            string TestCaseLogFail = "";
            foreach (TestCase t in tstCaseObj)
            {
                if (t.IsPass)
                {
                    TestCaseLogSuccess += "Test Case ID: " + t.TestId + ", Test Case: " + t.TestCaseDesc + ", Is Pass: " + t.IsPass + "\n";
                }
                else
                {
                    TestCaseLogFail += "Test Case ID: " + t.TestId + ", Test Case: " + t.TestCaseDesc + ", Is Pass: " + t.IsPass + "\n";
                }

            }
            MessageBox.Show("Testy Case Pass - Log \n\n" + TestCaseLogSuccess + "\n\nTest Case Fail\n\n" + TestCaseLogFail, "Test Case Log", MessageBoxButton.OK, MessageBoxImage.Information);

        }

        #region Validating DB Test Case - Manual
        private void btnDBTest_Click(object sender, RoutedEventArgs e)
        {
            tstCaseObj.Clear();
            DataTable mydtIdentity = OrganizationDAL.GetOrganizationUpdate(EmpId);
            CheckDBDataWithForm(mydtIdentity);
            if (mydtIdentity.Rows.Count == 0)
            {
                MessageBox.Show("Please Insert Record And Check The Data With DataBase", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            string TestCaseLogSuccess = "";
            string TestCaseLogFail = "";
            foreach (TestCase t in tstCaseObj)
            {
                if (t.IsPass)
                {
                    TestCaseLogSuccess += "Test Case ID: " + t.TestId + ", Test Case: " + t.TestCaseDesc + ", Is Pass: " + t.IsPass + "\n";
                }
                else
                {
                    TestCaseLogFail += "Test Case ID: " + t.TestId + ", Test Case: " + t.TestCaseDesc + ", Is Pass: " + t.IsPass + "\n";
                }
            }

            MessageBox.Show("Test Case Pass - Log \n\n" + TestCaseLogSuccess + "\n\nTest Case Fail -Log\n\n" + TestCaseLogFail, "Test Case Log", MessageBoxButton.OK, MessageBoxImage.Information);
        }
        private void CheckDBDataWithForm(DataTable mydtIdentity)
        {
            if (EmpType == "PE")
            {

                TestCase TestObj;
                int seed = 1;

                if (mydtIdentity.Rows.Count > 0)
                {
                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Employee ID should match";
                    if (EmpId != mydtIdentity.Rows[0][0].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Date Of Joining Information Should Match";

                    string x = DateTime.Parse(mydtIdentity.Rows[0][1].ToString()).ToShortDateString();
                    if (dpDOJ.Text != x)
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Designa Information Should Match";
                    if (cmbDesignation.Text != mydtIdentity.Rows[0][2].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Reporting To Information Should Match";
                    if (txtReportingTo.Text != mydtIdentity.Rows[0][3].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Recruited By Information Should Match";
                    if (txtRecruitedBy.Text != mydtIdentity.Rows[0][4].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Previous Employer Information Should Match";
                    if (txtPrevEmp.Text != mydtIdentity.Rows[0][7].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Year Of Experience Information Should Match";
                    if (txtYOP.Text != mydtIdentity.Rows[0][8].ToString() && txtYOP.Text == "0.00")
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Reffered By Information Should Match";
                    if (txtReferedBy.Text != mydtIdentity.Rows[0][9].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Refference Phone Number Information Should Match";
                    if (txtRefNO.Text != mydtIdentity.Rows[0][10].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Qualification Information Should Match";
                    if (cmbQualification.Text != mydtIdentity.Rows[0][5].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Other Qualification Information Should Match";
                    if (txtOtherQual.Text != mydtIdentity.Rows[0][6].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }


                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Heighest Qualification Certificate Information Should Match";
                    if (HQCertfPath == mydtIdentity.Rows[0][11].ToString() || (mydtIdentity.Rows[0][11].ToString() == "" && HQCertfPath == null))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }


                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Previous Employer Letter Information Should Match";

                    if (PrevEmpCertfPath == mydtIdentity.Rows[0][12].ToString() || (mydtIdentity.Rows[0][12].ToString() == "" && PrevEmpCertfPath == null))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }


                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Resume Information Should Match";
                    if (ResumePath == mydtIdentity.Rows[0][13].ToString() || (mydtIdentity.Rows[0][13].ToString() == "" && ResumePath == null))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }
            }
            else if (EmpType == "CE")
            {
                TestCase TestObj;
                int seed = 1;
                tstCaseObj.Clear();
                if (mydtIdentity.Rows.Count > 0)
                {
                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Employee ID should match";
                    if (EmpId != mydtIdentity.Rows[0][0].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Date Of Joining Information Should Match";
                    string x = DateTime.Parse(mydtIdentity.Rows[0][1].ToString()).ToShortDateString();
                    if (dpDOJ.Text != x)
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Designation Information Should Match";
                    if (cmbDesignation.Text != mydtIdentity.Rows[0][2].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Reporting To Information Should Match";
                    if (txtReportingTo.Text != mydtIdentity.Rows[0][3].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Recruited By Information Should Match";
                    if (txtRecruitedBy.Text != mydtIdentity.Rows[0][4].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Previous Employer Information Should Match";
                    if (txtPrevEmp.Text != mydtIdentity.Rows[0][7].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Year Of Experience Information Should Match";
                    if (txtYOP.Text != mydtIdentity.Rows[0][8].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Reffered By Information Should Match";
                    if (txtReferedBy.Text != mydtIdentity.Rows[0][9].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }

                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Refference Phone Number Information Should Match";
                    if (txtRefNO.Text != mydtIdentity.Rows[0][10].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                }

            }
        }


        #endregion

        #region Validating Test Case - Manual

        public void Validate()
        {
            if (EmpType == "PE")
            {
                int seed = 1;
                TestCase TestObj;
                TestObj = new TestCase();

                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "DOJ is mandatory";
                if (dpDOJ.SelectedDate.Value.ToString() != "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Designation is mandatory";
                if (cmbDesignation.SelectedIndex != 0)
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Recruited by is mandatory ";
                if (txtRecruitedBy.Text != "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Qualificaton Must be Selected";
                if (cmbQualification.SelectedIndex != 0)
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Other Qualf should be available if Qualification is Others";
                if (cmbQualification.SelectedIndex == 6)
                {
                    if (txtOtherQual.Text != "")
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Previous Employer Not Mandatory if no. of years exp is zero";
                if ((txtPrevEmp.Text == "" && txtYOP.Text == "") || (txtPrevEmp.Text != "" && txtYOP.Text != ""))
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Previous Employer must be available if prev employer is there";
                if ((txtPrevEmp.Text == "" && txtYOP.Text == "") || (txtPrevEmp.Text != "" && txtYOP.Text != ""))
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Reference number must be available if referred by some one";
                if ((txtPrevEmp.Text == "" && txtYOP.Text == "") || (txtPrevEmp.Text == "" && txtYOP.Text == "0.00") || (txtPrevEmp.Text != "" && txtYOP.Text != ""))
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }


                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Previous Employer Name should be in correct format";
                Regex nameRE = new Regex(@"^[a-zA-Z\s]+$");
                if (nameRE.IsMatch(txtPrevEmp.Text) || txtPrevEmp.Text == "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Years of Experience should not be alphabets";
                Regex exprefNoReg = new Regex(@"^\d{1,2}(\.\d{0,2})?$");
                //struggling
                if (exprefNoReg.IsMatch(txtYOP.Text) || txtYOP.Text == "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }

                if (exprefNoReg.IsMatch(txtYOP.Text))
                {
                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Years of Experience should be in correct format";
                    if (txtYOP.Text != "")
                    {
                        string[] x = txtYOP.Text.Split('.');

                        int y = 0;


                        if (x.Length == 1)
                        {
                            y = 0;
                        }
                        else
                        {
                            y = Int32.Parse(x[1]);
                        }
                        if (Int32.Parse(x[0]) > 99 || y > 12)
                        {

                            TestObj.IsPass = false;
                            tstCaseObj.Add(TestObj);
                        }
                        else
                        {
                            TestObj.IsPass = true;
                            tstCaseObj.Add(TestObj);
                        }
                    }




                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Referred by Name should be in correct format";
                if (nameRE.IsMatch(txtReferedBy.Text) || txtReferedBy.Text == "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }



                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Referred number should be in correct format";
                Regex refNoReg = new Regex(@"\d+$");
                if (refNoReg.IsMatch(txtRefNO.Text) || txtRefNO.Text == "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }



                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Highest Qualificaton file should exist in temp folder before saving";
                if (HQCertfPath != "" && HQCertfPath != null)
                {
                    if (File.Exists(HQCertfPath))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }

                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Previous Employer file should exist in temp folder before saving";
                if (PrevEmpCertfPath != "" && PrevEmpCertfPath != null)
                {
                    if (File.Exists(PrevEmpCertfPath))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }

                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Resume file should exist in temp folder before saving";
                if (ResumePath != "" && ResumePath != null)
                {
                    if (File.Exists(ResumePath))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }

                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                string hqtemp = HQCertfPath;
                string petemp = PrevEmpCertfPath;
                string resumetemp = ResumePath;
                btnSave_Click(null, null);
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Highest Qualificaton file should not exist in temp Folder after save";
                if (hqtemp != "" && hqtemp != null)
                {
                    if (File.Exists(hqtemp))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }

                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Previous Employer file should not exist in temp Folder after save";
                if (petemp != "" && petemp != null)
                {
                    if (File.Exists(petemp))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }

                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Resume file should not exist in temp Folder after save path";
                if (resumetemp != "" && resumetemp != null)
                {
                    if (File.Exists(resumetemp))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }

                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Highest Qualificaton file should exist in Employees Folder after save";
                if (HQCertfPath != "" && HQCertfPath != null)
                {
                    if (File.Exists(HQCertfPath))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }

                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Previous Employer file should exist in Employees Folder after save";
                if (PrevEmpCertfPath != "" && PrevEmpCertfPath != null)
                {
                    if (File.Exists(PrevEmpCertfPath))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }

                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Resume file should exist in Employees Folder after save path";
                if (ResumePath != "" && ResumePath != null)
                {
                    if (File.Exists(ResumePath))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }

                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }


                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "List should be cleared after save ";
                if (lstPaths.Count == 0)
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }



            }
            else if (EmpType == "CE")
            {
                int seed = 1;
                TestCase TestObj;
                TestObj = new TestCase();

                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "DOJ is mandatory";
                if (dpDOJ.SelectedDate.Value.ToString() != "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Designation is mandatory";
                if (cmbDesignation.SelectedIndex != 0)
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Recruited by is mandatory ";
                if (txtRecruitedBy.Text != "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Years of Exp Mandatory if Previous Employer Mentioned";
                if ((txtPrevEmp.Text == "" && txtYOP.Text == "") || (txtPrevEmp.Text != "" && txtYOP.Text != ""))
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Previous Employer must be available if prev employer is there";
                if ((txtPrevEmp.Text == "" && txtYOP.Text == "") || (txtPrevEmp.Text != "" && txtYOP.Text != ""))
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Reference number must be available if referred by some one";
                if ((txtPrevEmp.Text == "" && txtYOP.Text == "") || (txtPrevEmp.Text == "" && txtYOP.Text == "0.00") || (txtPrevEmp.Text != "" && txtYOP.Text != ""))
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Previous Employer Name should be in correct format";
                Regex nameRE = new Regex(@"^[a-zA-Z\s]+$");
                if (nameRE.IsMatch(txtPrevEmp.Text) || txtPrevEmp.Text == "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Years of Experience should be in correct format";
                Regex exprefNoReg = new Regex(@"^\d{1,2}(\.\d{0,2})?$");
                if (txtYOP.Text != "" && nameRE.IsMatch(txtYOP.Text))
                {
                    string[] x = txtYOP.Text.Split('.');

                    int y = 0;


                    if (x.Length == 1)
                    {
                        y = 0;
                    }
                    else
                    {
                        y = Int32.Parse(x[1]);
                    }
                    if (Int32.Parse(x[0]) > 99 || y > 12)
                    {

                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                }
                else if (nameRE.IsMatch(txtYOP.Text))
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);

                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Referred by Name should be in correct format";
                if (nameRE.IsMatch(txtReferedBy.Text) || txtReferedBy.Text == "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }


                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Referred number should be in correct format";
                Regex refNoReg = new Regex(@"\d+$");
                if (refNoReg.IsMatch(txtRefNO.Text) || txtRefNO.Text == "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
            }
        }

        #endregion


        #region Testing Controls
        private void btnTestControls_Click(object sender, RoutedEventArgs e)
        {
            tstCaseObj.Clear();
            ValidateControls();
            string TestCaseLogSuccess = "";
            string TestCaseLogFail = "";
            foreach (TestCase t in tstCaseObj)
            {
                if (t.IsPass)
                {
                    TestCaseLogSuccess += "Test Case ID: " + t.TestId + ", Test Case: " + t.TestCaseDesc + ", Is Pass: " + t.IsPass + "\n";
                }
                else
                {
                    TestCaseLogFail += "Test Case ID: " + t.TestId + ", Test Case: " + t.TestCaseDesc + ", Is Pass: " + t.IsPass + "\n";
                }

            }
            MessageBox.Show("Testy Case Pass - Log \n\n" + TestCaseLogSuccess + "\n\nTest Case Fail\n\n" + TestCaseLogFail, "Test Case Log", MessageBoxButton.OK, MessageBoxImage.Information);


        }

        private void ValidateControls()
        {
            TestCase TestObj;
            int seed = 1;
            if (EmpType == "PE")
            {

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Grid Qualification should be visible only for PE";
                if (grdqulf.Visibility == Visibility.Visible)
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }


                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Grid Documents should be visible only for PE";
                if (docgrid.Visibility == Visibility.Visible)
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
            }
            else if (EmpType == "CE")
            {
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Grid Qualification should not be visible";
                if (grdqulf.Visibility == Visibility.Collapsed)
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }


                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Grid Documents should not be visible";
                if (docgrid.Visibility == Visibility.Collapsed)
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
            }
        }

        #endregion

        private void txtPrevEmp_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        #endregion

        private void txtReportingTo_LostFocus(object sender, RoutedEventArgs e)
        {
            bool flag = true;
            if (txtReportingTo.Text != null && txtReportingTo.Text != "")
            {
                flag = false;
               // lblReportingTo.Foreground = System.Windows.Media.Brushes.DimGray;
                
                for (int i = 0; i < empList.Count; i++)
                {
                    if (txtReportingTo.Text.ToUpper() == empList[i].id.ToUpper())
                    {
                        txtReportingTo.Text = empList[i].name;
                        flag = true;
                        break;
                    }
                    if (txtReportingTo.Text.ToUpper() == empList[i].name.ToUpper())
                    {
                       // txtReportingTo.Text = empList[i].id;
                        flag = true;
                        break;
                    }
                }
                if (flag == false)
                {
                   // MessageBox.Show("Reporting to Not a Valid Employee", "Reporting To", MessageBoxButton.OK, MessageBoxImage.Warning);
                   // lblReportingTo.Foreground = System.Windows.Media.Brushes.Red; 
                }
            }
        }

        private void txtRecruitedBy_LostFocus(object sender, RoutedEventArgs e)
        {
           // lblRecruitedBy.Foreground = System.Windows.Media.Brushes.DimGray;
            bool flag = true;
            if (txtRecruitedBy.Text != null && txtRecruitedBy.Text != "")
            {
                flag = false;
                for (int i = 0; i < empList.Count; i++)
                {
                    if (txtRecruitedBy.Text.ToUpper() == empList[i].id.ToUpper())
                    {
                        txtRecruitedBy.Text = empList[i].name;
                        flag = true;
                        break;
                    }
                    if (txtRecruitedBy.Text.ToUpper() == empList[i].name.ToUpper())
                    {
                        //txtRecruitedBy.Text = empList[i].id;
                        flag = true;
                        break;
                    }
                }
            }
            if (flag == false)
            {
               // MessageBox.Show("Recruited by Not a valid Employee", "Recruited By", MessageBoxButton.OK, MessageBoxImage.Warning);
               // lblRecruitedBy.Foreground = System.Windows.Media.Brushes.Red;
              
            }
        }

        private void txtRecruitedBy_TextChanged(object sender, RoutedEventArgs e)
        {
         
        }

        private void txtRecruitedBy_GotFocus(object sender, RoutedEventArgs e)
        {
        
        }

        

    }
}
